package com.lql.lqlreader

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.jaeger.library.StatusBarUtil
import com.lql.lqlreader.util.ToolbarHelper

abstract class BaseActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        super.setContentView(R.layout.activity_base_original)
    }

    override fun setContentView(layoutResID: Int) {
        ToolbarHelper.setContentView(this, layoutResID)
        setStatusBar()
    }

    override fun setContentView(view: View) {
        ToolbarHelper.setContentView(this, view)
        setStatusBar()
    }

    override fun onSupportNavigateUp(): Boolean {
        finish()
        return super.onSupportNavigateUp()
    }

    fun setLeftTitleAndDoNotDisplayHomeAsUp(title: String) {
        ToolbarHelper.setLeftTitle(supportActionBar!!, title)
        ToolbarHelper.showHomeAsUp(supportActionBar!!)
    }

    fun setLeftTitleAndDisplayHomeAsUp(title: String) { // 显示Home键
        if (supportActionBar != null) {
            ToolbarHelper.setLeftTitle(supportActionBar!!, title)
            ToolbarHelper.showHomeAsUp(supportActionBar!!)
        }

    }

    private fun setStatusBar() { // 设置状态栏
        StatusBarUtil.setColor(this, resources.getColor(R.color.colorPrimary), StatusBarUtil.DEFAULT_STATUS_BAR_ALPHA)
    }
}